

$(document).ready(function() {
    /*查询我的申请*/
    query();



});
var projectId="";
var query=function () {
    $('#dataTable').dataTable({
        "bDeferRender":true,
        "sAjaxDataProp":"data.projectList",
        "sAjaxSource":"http://localhost:8080/project/queryMyProject?stuNum="+20151000,
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function( oSettings ) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>"
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",

        "aoColumns": [
            {"mDataProp":"projectId"},
            {"mDataProp":"stuNum"},
            {"mDataProp":"stuName"},
            {"mDataProp":"stuSex",
                "mRender": function(data) {
                    var value = "男";
                    if (data==1){
                        value = "女";
                    }
                    return value;
                }
            },
            {"mDataProp":"academyName"},
            {"mDataProp":"termYear"},
            {"mDataProp":"termNum"},
            {"mDataProp":"projectName"},
            {"mDataProp":"projectContent"},
            {"mDataProp":"projectStartDate"},
            {"mDataProp":"projectEndtDate"},
            {"mDataProp":"projectContactPeople"},
            {"mDataProp":"projectPhonenum"},
            {"mDataProp":"projectPlatform"},
            {"mDataProp":"projectState",
                "mRender": function(data) {
                    var value = "<a href='#'><span id='re-apply' class='label label-danger mr10 mb10'>未通过</span></a>";
                    if (data==1){
                        value = "<a href='#'><span id='download' class='label label-success mr10 mb10'>已通过</span></a>";
                    }if (data==2){
                        value = "<a href='#'><span id='edit-btn' class='label label-yellow mr10 mb10'>审核中</span></a>";
                    }
                    return value;
                }
            }
        ],

    })
};

$(document).on('click', '#re-apply', function () {
    //获取projectId
    var $projectId = $(this).parents("tr").children(0).eq(0).text();

    //页面层
    layer.open({
        type: 2,
        title: '重新申请',
        area: ['1400px', '650px'],
        content: ['editProject.html?projectId='+$projectId, 'no']
    })
})

$(document).on('click', '#edit-btn', function () {
    //获取projectId
    var $projectId = $(this).parents("tr").children(0).eq(0).text();

    //页面层
    layer.open({
        type: 2,
        title: '更新申请',
        area: ['1400px', '650px'],
        content: ['editProject.html?projectId='+$projectId, 'no']
    })
})

$(document).on('click', '#download', function() {
    /*stuNum,stuName,stuSex,academyName,
                 termYear,termNum,startDate,endDate,
                contact,contactPhone,platform,proName,
                proContent*/
    var stuNum=$(this).parents("tr").children(0).eq(1).text();
    var stuName=$(this).parents("tr").children(0).eq(2).text();
    var stuSex=$(this).parents("tr").children(0).eq(3).text();
    var academyName=$(this).parents("tr").children(0).eq(4).text();
    var termYear=$(this).parents("tr").children(0).eq(5).text();
    var termNum=$(this).parents("tr").children(0).eq(6).text();
    var startDate=$(this).parents("tr").children(0).eq(9).text();
    var endDate=$(this).parents("tr").children(0).eq(10).text();
    var contact=$(this).parents("tr").children(0).eq(11).text();
    var contactPhone=$(this).parents("tr").children(0).eq(12).text();
    var platform=$(this).parents("tr").children(0).eq(13).text();
    var proName=$(this).parents("tr").children(0).eq(7).text();
    var proContent=$(this).parents("tr").children(0).eq(8).text();

    $.ajax({
        url: "http://localhost:8080/project/download",
        type: "GET",
        async: true,
        data: "stuNum=" + stuNum+"&stuName="+stuName+"&stuSex="+stuSex+"&academyName="+academyName+"&termYear="+termYear+"&termNum="+termNum+
              "&startDate="+startDate+"&endDate="+endDate+"&contact="+contact+"&contactPhone="+contactPhone+"&platform="+platform+"&proName="+proName+"&proContent="+proContent,
        dataType: "json",
        success:function () {
            layer.alert("暑期社会实践表已成功保存到桌面！");
        },
        error:function () {
            layer.alert("保存暑期社会实践表失败！请重新尝试！");
        }
    });

});